<?php
// +----------------------------------------------------------------------
// | EtrolPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Author: Author: HCZ <huangchengze@etrol.com>
// +----------------------------------------------------------------------

namespace app\alarm\controller;

use app\common\controller\Admin;
use app\alarm\controller\api\Alarm as AlarmApi;

/**
 * 字典管理
 * @package app\admin
 */
class Alarm  extends Admin{
	protected $api;
	
	public function _initialize()
	{
		parent::_initialize();
		$this->api = new AlarmApi();
	}
	
	/**
	 * 待处理
	 * @param string $alarmId
	 */
	public function toHandle($alarmId = null){
		$data['id'] = $alarmId;
		$data['status'] = 1;
		return $this->api->edit($data);
	}
	
	/**
	 * 忽略
	 * @param string $alarmId
	 */
	public function ignore($alarmId = null){
		$data['id'] = $alarmId;
		$data['status'] = 2;
		return $this->api->edit($data);
	}
	/**
	 * 处理报警
	 * @param string $alarmId
	 */
	public function alarmHandling($alarmId = null){
		if(IS_POST){
			$data = input('post.');
			$data['status'] = 3;
			$data['endTime'] = time();
			$data['operationId'] = session('user_auth.id');
			return $this->api->alarmHandling($data);
		}
		$alarm = $this->api->getAlarms($alarmId)->getData();
		$this->assign('info',$alarm['data'][0]);
		return $this->fetch();
	}
}